package com.apes.enquiry.enquiry.model;

import com.apes.enquiry.product.model.Category;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.fileserver.File;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * 类描述：询价配件
 *
 * @ClassName EnquiryItem
 * @Description 描述
 * @Author wushilong
 * @Date 2023/3/15 17:30
 * @Version 1.0
 */

@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = EnquiryItem.CONST_TABLE_NAME)
public class EnquiryItem extends BaseModel {

    public static final String CONST_TABLE_NAME = "sp_mas_enquiry_item";

    @Id
    @Column(name = "id", length = 10)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "询价明细", padding = 8)
    @Comment("编码")
    private String id;

    @Column(name = "enquiry_id", length = 32, nullable = false)
    @Comment("询价单号")
    private String enquiryId;

    @Column(name = "enquiry_require_id", length = 32, nullable = false)
    @Comment("询价需求id")
    private String enquiryRequireId;

    @Column(name = "oe", length = 32)
    @Comment("零件号")
    private String oe;

    @Column(name = "category_id", length = 32)
    @Comment("标准名称")
    private String categoryId;

    @Column(name = "category_name", length = 32)
    @Comment("标准名称")
    private String categoryName;

    @Transient
    private Category category;//标准名称

    @File
    @Lob
    @Basic(fetch = FetchType.LAZY)
    @Column(name = "epc_picture", columnDefinition = "CLOB")
    @Comment("EPC图片")
    private String epcPicture;

    @Column(name = "state", length = 32, nullable = false)
    @Comment("状态")
    private String state;//take_effect(生效), expired(作废)

    @Column(name = "price", length = 32)
    @Comment("4s价格")
    private Double price;


    @Column(name = "not_quote_qty", length = 32)
    @Comment("未报价供应商数量")
    private Integer notQuoteQty;

    @Column(name = "quote_qty", length = 32)
    @Comment("已报价供应商数量")
    private Integer quoteQty;

    @Column(name = "lack_quote_qty", length = 32)
    @Comment("报缺货供应商数量")
    private Integer lackQuoteQty;

    @Column(name = "send_back_qty", length = 32)
    @Comment("退回供应商数量")
    private Integer sendBackQty;

    @Column(name = "product_rule", nullable = false, columnDefinition = "number(1,0) default 1")
    @Comment("带安标记")
    private boolean productRule;

    @Transient
    private List quoteResult = new ArrayList<>();//系统报价

    @Transient
    private Integer qty;//数量

    @Transient
    private String note;//备注

    @Transient
    private String classifyId;//品类

    @Transient
    private String classifyName;//品类

    @Transient
    private String productId;//ERP系统商品id

    @Transient
    private String thisPicture;//给第三方平台的图片地址

    @Transient
    private String smartEpcPartName; // 服务方案上的 partName - 给巴图鲁用

    public Category getCategory() {
        if (category == null){
            Category category = new Category();
            category.setId(categoryId);
            category.setName(categoryName);
            this.category = category;
        }
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }
}
